/***********************************************************************************/
/* Code license:  GNU General Public License v3                                    */
/* Main page:     https://code.google.com/p/library-cross-platform/                */
/* Issue tracker: https://code.google.com/p/library-cross-platform/issues/list     */
/***********************************************************************************/

#ifndef _ASCII_PARSER_STATE_10_JUN_2011_
#define _ASCII_PARSER_STATE_10_JUN_2011_

#include "parserstate.h"
#include "unary_functions.h"

using namespace std;


typedef eof_string<char> ch_eof_string;

typedef struct _tag_param_value
{
  string name;
  string value;
}param_value;

class asciiparser : public parserstate
{
public:
  asciiparser();
  asciiparser(std::istream*);
  virtual ~asciiparser();

protected:
/******************************************************************************
Description:  check is end-of string
IN:  char
OUT: if end-of string then true else false
******************************************************************************/
  virtual bool eos(char &c); //check is end-of string

/******************************************************************************
Description:  remove spaces from string
IN:  string reference
OUT: none
******************************************************************************/
  void remove_space(string& str);

/******************************************************************************
Description:  remove eof from string (eod-of-string is: '\n', '\r')
IN:  string reference
OUT: none
******************************************************************************/
  void remove_eof_string(string& str);

/******************************************************************************
Description: skip empty lines from the stream
IN:  none.
OUT: READ_FILE_RESULT - result.
******************************************************************************/
  virtual READ_FILE_RESULT skipEmptyLines();

/******************************************************************************
Description: skip empty characters in the input string.
             test starts from the 'index'.
             Empty characters: '\r', '\n', '\t', ' '

IN:  input string
IN:  start index
OUT: next index after the latest empty character.
******************************************************************************/
  virtual int skipEmptyData(const string &raw_data, int index);

/******************************************************************************
Description: the string separates for 2 parts.
             result is new string befor separator.

IN:   input string data
IN:   start index for the input string data. from this
      index starts string analyses.
IN:   stop symbol.
IN:   result - new string data
OUT:  new index. new index is after stop symbol.
******************************************************************************/
  virtual int getDataFromString(const string &raw_data, int raw_index, const char separator, string &ret_data);

/******************************************************************************
Description: the string separates for 2 parts.
             result is new string befor separator.
             stop symbol is: ','

IN:   input string data
IN:   start index for the input string data. from this
      index starts string analyses.
IN:   result - new string data
OUT:  new index. new index is after stop symbol.
******************************************************************************/
  virtual int getDataFromString(const string &raw_data, int row_index, string &ret_data);

/******************************************************************************
Description: get string parameter from the input string.
IN: input string data
IN: start index for the input string data. from this
    index starts string analyses
IN: symbol separates the parameters
IN: parameter index to search
IN: result - new string data
OUT: new index after found parameter.
******************************************************************************/
  virtual int getParamFromData(const string &raw_data, int raw_index, const char separator, int paramid, string &ret_data);

/******************************************************************************
Description: get string parameter from the input string.
             symbol separates the parameters is ','
IN: input string data
IN: start index for the input string data. from this
    index starts string analyses
IN: parameter index to search
IN: result - new string data
OUT: new index after found parameter.
******************************************************************************/
  virtual int getParamFromData(const string &raw_data, int raw_index, int paramid, string &ret_data);

/******************************************************************************
Description: get string after symbol separates
IN:  input string
IN:  symbol separator
OUT: new string after separator
******************************************************************************/
  virtual string parseDataParameter(const string &in, const char c);

/******************************************************************************
Description: get data before separator and after separator
IN: input string data
IN: start index for the input string data. from this
    index starts string analyses
IN: symbol separates the parameters
OUT: param_value
******************************************************************************/
  virtual param_value parseDataParameter(const string &in, int index, const char separator);

/******************************************************************************
Description: copy input string from the 'index' to
             the 'out' string before symbol separator 'till'
IN:  input string data
IN:  start index for the input string data. from this
     index starts string analyses
IN:  symbol separates the parameters
IN:  new string
OUT: new index after symbol separator
******************************************************************************/
  virtual int strcpytill(const string &in, int index, const char till, string *out);

/******************************************************************************
Description: check the is tring is comment or not.
             NOTE: in this calss this function return false always.
                   you must implement this function for your class.
example how to geat raw data for analyses: string rawdata = getRawData();
IN:  none
OUT: true - this is comment string. fasle - this is not comment string
******************************************************************************/
  virtual bool isComment();

/******************************************************************************
Description: check is the input string empty or not.
             the string empty if: in.at(0) == '\n' or '\r' or '\0'
             additional chek for (in.length() == 0). If this expression is true
             then result is true also.
IN: string
OUT: true - string is empty otherwise false
******************************************************************************/
  virtual bool isEmptyString(const string &in);

/******************************************************************************
***          STATE FUNCTION DECLARATION                                     ***
******************************************************************************/
  DECLARE_START_STATE_FUNCTION()

};

#endif
